﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MyTetris
{
    public partial class FrmMain : Form
    {
        private BaseBlock nextBlock = null;

        public FrmMain()
        {
            InitializeComponent();

        }

        private void Form1_Load(object sender, EventArgs e)
        {
            GameEngine.Instance.InvalidteFieldEvent += Instance_InvalidteFieldEvent;
           
        }

        private void Instance_InvalidteFieldEvent()
        {
            MainContainer.Invalidate();
        }

        private void panel1_Paint(object sender, PaintEventArgs e)
        {

        }


        private void MainContainer_Paint(object sender, PaintEventArgs e)
        {
            GameEngine.Instance.DrawAllSquares(e.Graphics);
        }

        //按键控制
        private void FrmMain_KeyDown(object sender, KeyEventArgs e)
        {
            switch(e.KeyCode)
            {
                case Keys.S://控制下降
                    GameEngine.Instance.CurrentBlock.MoveDown();
                    break;
                case Keys.W://控制旋转
                    GameEngine.Instance.CurrentBlock.Rotate();
                    break;
                case Keys.F://手动出现下一个方块（测试用）
                    GameEngine.Instance.RestartGame();
                    break;
                case Keys.A://控制左移
                    GameEngine.Instance.CurrentBlock.MoveLeft();
                    break;
                case Keys.D://控制右移
                    GameEngine.Instance.CurrentBlock.MoveRight();
                    break;
            }
            MainContainer.Invalidate();//强制刷新
        }

        private void MainContainer_Click(object sender, EventArgs e)
        {

        }
        private void nextPreviewContainer_Click(object sender, EventArgs e)
        {

        }

       
        private void nextPreviewContainer_Paint(object sender, PaintEventArgs e)
        {
            if (nextBlock != null)
                nextBlock.Draw(e.Graphics);
        }

        private void button_NewGame_Click(object sender, EventArgs e)
        {
            
        }

        private void button_Stop_Click(object sender, EventArgs e)
        {

        }

        private void button_Quit_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            frmAboutMe frm= new frmAboutMe();
            frm.ShowDialog();
        }

        private void btnIntroduce_Click(object sender, EventArgs e)
        {
            frmIntroduce frm = new frmIntroduce();
            frm.ShowDialog();
        }
    }
}
